import * as constants from './constants';
import { fromJS } from 'immutable';
import axios from 'axios';

const setHomeInfo = (data) => ({
  type: constants.INIT_HOME_INFO,
  data: fromJS(data)
});

export const initHomeInfo = () => {
  return (dispatch) => {
    axios.get('/api/getHomeInfo').then((res) => {
      const data = res.data;
      if (data.code === 200) {
        dispatch(setHomeInfo(data.data));
      } else {
        alert('网络错误：请求接口失败');
      }
    }).catch((error) => {
      console.log('error', error);
    });
  }
}